﻿using System;
using System.Collections.Generic;
using System.Text;

namespace TheLogWatcher
{
    public class PredefinedLogFormats
    {
        private static List<LogFormat> formats = new List<LogFormat>();

        /// <summary>
        ///     Static construction for initialization
        /// </summary>
        static PredefinedLogFormats() {
            formats.Add(Log4jDE());
            formats.Add(Log4jEN());
            formats.Add(WindowsUpdateLog());
            formats.Add(WindowsWTUpdater());
        }

        public static List<LogFormat> Formats
        {
            get { return formats; }
        }

        private static LogFormat Log4jDE()
        {
            LogFormat format = new LogFormat();
            format.Name = "Log4j DE";
            format.addPart("Date", 80, @"", @"\d{2}\.\d{2}\.\d{4}", "dd.MM.yyyy");
            format.addPart("Time", 70, @"\s", @"\d{2}:\d{2}:\d{2}", "HH:mm:ss");
            format.addPart("Type", 40, @"\s\[", @"\w+?");
            format.addPart("Package", 340, @"\]\W+?", @".+?");
            format.addPart("Log", 400, @"\W-\W", null);
            return format;
        }

        private static LogFormat Log4jEN()
        {
            LogFormat format = new LogFormat();
            format.Name = "Log4j EN";
            format.addPart("Date", 80, @"", @"\d{4}-\d{2}-\d{2}", "yyyy-MM-dd");
            format.addPart("Time", 70, @"\s", @"\d{2}:\d{2}:\d{2}", "HH:mm:ss");
            format.addPart("Type", 40, @"\s\[", @"\w+?");
            format.addPart("Package", 340, @"\]\W+?", @".+?");
            format.addPart("Log", 400, @"\W-\W", null);
            return format;
        }

        private static LogFormat WindowsUpdateLog()
        {
            LogFormat format = new LogFormat();
            format.Name = "WindowsUpdateLog";
            format.addPart("Date", 80, @"", @"\d{4}-\d{2}-\d{2}", "yyyy-MM-dd");
            format.addPart("Time", 70, @"\t", @"\d{2}:\d{2}:\d{2}", "HH:mm:ss");
            format.addPart("Log", 600, @".+?\t", null);
            return format;
        }

        private static LogFormat WindowsWTUpdater()
        {
            LogFormat format = new LogFormat();
            format.addPart("Date", 80, @"\w+?,\s", @"\d{2}\s\w+?\s\d{4}");
            format.addPart("Time", 70, @"\s", @"\d{2}:\d{2}:\d{2}", "HH:mm:ss");
            format.addPart("Log", 600, @" : ", null);
            return format;
        }
    }
}
